package run.demo;

import brave.baggage.BaggageField;
import brave.baggage.CorrelationScopeConfig;
import brave.context.slf4j.MDCScopeDecorator;
import brave.propagation.CurrentTraceContext;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

public class Demo {
    // service
    @Autowired
    BaggageField countryCodeField;

    @Bean
    BaggageField countryCodeField() {
        return BaggageField.create("country-code");
    }

    @Bean
    CurrentTraceContext.ScopeDecorator mdcScopeDecorator(BaggageField countryCodeField) {
        return MDCScopeDecorator.newBuilder()
                .clear()
                .add(CorrelationScopeConfig.SingleCorrelationField.newBuilder(countryCodeField)
                        .flushOnUpdate()
                        .build())
                .build();
    }
    @Test
    public void verify(){
        countryCodeField.updateValue("new-value");
    }

}
